
TARGETCLASS =conv040
# Optimization level, put in comment for debugging
OPTIMIZATION = -g -O0


CROSS_COMPILE =
CC = $(CROSS_COMPILE)clang
SIZE = $(CROSS_COMPILE)size
OBJCOPY = $(CROSS_COMPILE)objcopy


# Output directories
BIN = bin
OBJ = obj

#binary location/name
OUTPUT := $(BIN)/$(TARGETCLASS)

CFLAGS += -Wall -std=c99
CFLAGS += $(OPTIMIZATION) $(INCLUDES)

C_OBJECTS = main.o


#build rules

all: $(BIN) $(OBJ) $(TARGETCLASS) 
$(BIN) $(OBJ):
	mkdir $@

define RULES
C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))

$(1): $$(C_OBJECTS_$(1))
#	$(CC) $(LDFLAGS) -o $(OUTPUT)-$$@.elf $$^
	$(CC) $(LDFLAGS) -o $(OUTPUT).elf $$^

$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
	$(CC) $(CFLAGS) -D$(1) -c -o $$@ $$<

endef

$(foreach MEMORY, $(TARGETCLASS), $(eval $(call RULES,$(MEMORY))))

clean:
	-rm -f $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf 